# -*- coding: utf-8 -*-
from sqlalchemy import Column,String,Integer,Text,Binary,Boolean,DateTime,Enum,Float,BigInteger
from adminApp.extensions import db
from .base import BaseModel
import uuid


def gen_id():
    return uuid.uuid4().hex

class HardDisk(BaseModel, db.Model):
    '''设备当前硬盘记录'''
    id = db.Column(db.String(32), default=gen_id, primary_key=True)
    enclosure = Column(Integer)  # 盘柜号
    slot = Column(Integer)  # 槽位号
    sas_address = Column(String(128))
    state = Column(String(128))
    size = Column(BigInteger)  # 空间大小
    sectors = Column(BigInteger)  # 扇区数目
    model_number = Column(String(128))  # 批号
    manufacturer = Column(String(128))  # 品牌
    firmware_revision = Column(String(128))  # 固件版本
    serial = Column(String(256))  # 磁盘 PN
    serial_no = Column(String(256))  # 磁盘 PN
    guid = Column(String(256))  # 磁盘 SN
    protocol = Column(String(256))  # 磁盘接口 ata scsi
    drive_type = Column(String(256))  # 磁盘类型 ssh sas
    is_root_disk = Column(Boolean, default=False)  # 是否系统盘
    name = Column(String(256))  # 在系统中的盘符 sda sdb sdc 等
    fstype = Column(String(64))
    #Lsblk_state = Column(String(64))
    #Lsblk_tran = Column(String(64))
    #Lsblk_serial = Column(String(128))
    rota = Column(Integer)
    mountpoint = Column(String(1024))
    wwn = Column(String(256))
    read_write = Column(Boolean, default=False)     # True 没有错误，False=有读写错误
    temperature = Column(Integer)
    total = Column(BigInteger)
    used = Column(BigInteger)
    free = Column(BigInteger)
    percent = Column(Float)

    # 备注
    remark = Column(Text)

    machine_id = db.Column(db.Integer, db.ForeignKey('machine.id', ondelete='CASCADE'), nullable=False, index=True)
    machine = db.relationship('Machine', back_populates='hard_disks')